<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;

class RequestAdmins extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
          'username'=>[
            'required',//必须输入
//            'min:6',//最小6位
//            'max:30',//最大30
            'regex:/^[A-Za-z0-9_\x{4e00}-\x{9fa5}]{3,30}+$/u',
            Rule::unique('admins')->ignore($this->input('id',0))//修改数据时，忽略当前数据id对应的字段验证唯一性
          ],
          'phone'=>[
            'required',
            'regex:/^1[3456789]\d{9}$/',
            Rule::unique('admins')->ignore($this->input('id',0))
          ],
          'email'=>'nullable|email',
          'pass'=>[
            'required',
//            'regex:/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,18}$/',
            'regex:/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,18}$/',
          ],
          'nickname'=>[
            'nullable',
            'max:30',
          ],
          'realname'=>[
            'nullable',
            'max:50',
//            'regex:/^[\x{4e00}-\x{9fa5}]+$/u',
          ],
          'sex'=>[
            'required',
            Rule::in([0, 1, 2]),
          ],
        ];
    }

    public function messages()
    {
        return [
          'username.required'=>'请输入用户名！',
          'username.regex'=>'用户名由3-30位数字或字母、汉字、下划线组成！',
          'username.unique'=>'用户名已被注册！',
          'phone.required'=>'请输入手机号！',
          'phone.regex'=>'手机号格式错误',
          'phone.unique'=>'手机号已被注册！',
          'email.email'=>'邮箱格式错误！',
          'pass.required'=>'请输入密码！',
          'pass.regex'=>'密码必须同时包含数字和字母的6-18位字符！',
          'nickname.max'=>'昵称最多输入30位！',
          'realname.max'=>'真实姓名最多输入50位！',
//          'realname.regex'=>'真实姓名最多输入50位！',
          'sex.in'=>'性别只能选择男、女或保密',

        ];
    }
}
